
package graphics3d;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;


public class KeyboardController implements KeyListener {

    private final Scene scene;
    private final Object3d object;
    
    private final int speed = 10;
    
    private static final char LEFT = 'a';
    private static final char RIGHT = 'd';
    private static final char UP = 'w';
    private static final char DOWN = 's';
    private static final char BACK = 'b';
    private static final char FORWARD = 'f';
    private static final char ROTATE_Z_POS = '7';
    private static final char ROTATE_Z_NEG = '9';
    private static final char ROTATE_X_POS = '2';
    private static final char ROTATE_X_NEG = '8';
    private static final char ROTATE_Y_POS = '6';
    private static final char ROTATE_Y_NEG = '4';
    private static final char ROTATE_PP_X_POS = 'k';
    private static final char ROTATE_PP_X_NEG = 'i';
    private static final char ROTATE_PP_Y_POS = 'l';
    private static final char ROTATE_PP_Y_NEG = 'j';
    private static final char ROTATE_PP_Z_POS = 'u';
    private static final char ROTATE_PP_Z_NEG = 'o';
    private static final char SCALE_POS = '+';
    private static final char SCALE_NEG = '-';
    private static final char RESET = 'r';
    private static final char ROTATE_PP_LINE = 'q';
    
    public KeyboardController(Scene scene, Object3d object) {
        
        this.scene = scene;
        this.object = object;
        
    }
    
    @Override
    public void keyTyped(KeyEvent e) {
        
        switch (e.getKeyChar()) {
            case ROTATE_PP_LINE: object.RotatePPLine(1*speed);
                                 break;
            case LEFT: object.transfer(-0.2*speed, 0, 0);
                       break;
            case RIGHT: object.transfer(0.2*speed, 0, 0);
                        break;
            case UP: object.transfer(0, 0.2*speed, 0);
                     break;
            case DOWN: object.transfer(0, -0.2*speed, 0);
                       break;
            case ROTATE_Z_POS: object.rotateZ(1*speed);
                             break;
            case ROTATE_Z_NEG: object.rotateZ(-1*speed);
                             break;
            case ROTATE_X_POS: object.rotateX(1*speed);
                             break;
            case ROTATE_X_NEG: object.rotateX(-1*speed);
                             break;
            case ROTATE_Y_POS: object.rotateY(1*speed);
                             break;
            case ROTATE_Y_NEG: object.rotateY(-1*speed);
                             break;
            case BACK: object.transfer(0, 0, -0.2*speed);
                       break;
            case FORWARD: object.transfer(0, 0, 0.2*speed);
                       break;
            case SCALE_POS: object.scale(1.1, 1.1, 1.1);
                            break;
            case SCALE_NEG: object.scale(0.9, 0.9, 0.9);
                            break;
            case ROTATE_PP_X_POS: object.rotatePPX(1*speed);
                                  break;
            case ROTATE_PP_X_NEG: object.rotatePPX(-1*speed);
                                  break;
            case ROTATE_PP_Y_POS: object.rotatePPY(1*speed);
                                  break;
            case ROTATE_PP_Y_NEG: object.rotatePPY(-1*speed);
                                  break;
            case ROTATE_PP_Z_POS: object.rotatePPZ(1*speed);
                                  break;
            case ROTATE_PP_Z_NEG: object.rotatePPZ(-1*speed);
                                break;
            case RESET: object.reset();
                        break;
        }
        scene.repaint();
        
        
    }

    @Override
    public void keyPressed(KeyEvent e) {
        
    }

    @Override
    public void keyReleased(KeyEvent e) {
        
    }
    
}
